"""
账单产品服务
"""

from jlpay.services.base_service import BaseService
from jlpay.model.bill import (
  AccountFileDownloadRequest, AccountFileDownloadResponse,
  TransChargeQueryRequest, TransChargeQueryResponse,
  SettleBillQueryRequest, SettleBillQueryResponse
)


class BillService(BaseService):
  """账单产品服务类"""

  def __init__(self, config):
    """
    初始化账单产品服务

    Args:
        config: OrgConfig实例
    """
    super().__init__(config)

  def get_api_url(self, request_class, api_path=None):
    """
    获取API URL
    
    Args:
        request_class: 请求类
        api_path: 接口路径
        
    Returns:
        完整的API URL
    """
    base_url = self.config.url
    
    if api_path:
        return f"{base_url}{api_path}"
    
    # 直接使用Request类中定义的完整API路径
    api_url = getattr(request_class, 'API_URL', '')
    
    if not api_url:
        # 如果没有定义API_URL，使用默认路径
        return f"{base_url}/open/bill"
    
    # 直接返回完整路径
    return f"{base_url}{api_url}"

  def download_account_file(self, request):
    """
    对账下载

    Args:
        request: AccountFileDownloadRequest实例

    Returns:
        AccountFileDownloadResponse实例
    """
    return self.post(request, AccountFileDownloadResponse)

  def query_trans_charge(self, request):
    """
    手续费查询

    Args:
        request: TransChargeQueryRequest实例

    Returns:
        TransChargeQueryResponse实例
    """
    return self.post(request, TransChargeQueryResponse)

  def query_settle_bill(self, request):
    """
    商户结算账单查询

    Args:
        request: SettleBillQueryRequest实例

    Returns:
        SettleBillQueryResponse实例
    """
    return self.post(request, SettleBillQueryResponse)